/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.tool;

import com.minecraft.moonlake.legendaryweaponrel.weapons.WeaponAbstractEntityDamageByEntity;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;

public class Simon extends WeaponAbstractEntityDamageByEntity {

    public Simon() {
        super("simon", "&b西蒙之歌", Material.IRON_SWORD);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7每次攻击目标自身获得&a速度1 10s &7效果",
                "&7并且有几率 &a10% &7触发击退5的附魔效果"
        };
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Player player, LivingEntity entity) {
        // 给予效果
        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10 * 20, 0));
        // 判断是否触发击退
        int value = (int) (Math.random() * 100);
        int chance = value <= 10 ? 1 : -1; // 几率 10 触发, 否则无效

        if(chance == 1) {
            // 触发击退效果
            Vector vector = player.getLocation().getDirection().normalize();
            entity.setVelocity(vector.multiply(8d).setY(0.3d));
        }
    }
}
